import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from "axios";
import VueAxios from "vue-axios";
import vuetify from './plugins/vuetify';
// 动画
import animated from "animate.css";
import "./assets/css/index.css";
import "./assets/css/iconfont.css";
import "./assets/css/markdown.css";
// vue 页面分享
import Share from "vue-social-share";
import "vue-social-share/dist/client.css";
// vue 弹幕墙
import { vueBaberrage } from "vue-baberrage";
// 日期
import moment from "moment";
// 无限加载
import InfiniteLoading from "vue-infinite-loading";
// 高亮
import "highlight.js/styles/atom-one-dark.css";
// vue 图片预览
import VueImageSwipe from "vue-image-swipe";
import "vue-image-swipe/dist/vue-image-swipe.css";
// 进度条
import NProgress from "nprogress";
import "nprogress/nprogress.css";
// 自定义
import config from "./assets/js/config";
import Toast from "./components/toast";


Vue.config.productionTip = false;
Vue.prototype.config = config;
Vue.use(VueAxios, axios);
Vue.use(InfiniteLoading);
Vue.use(VueImageSwipe);
Vue.use(vueBaberrage);
Vue.use(animated);
Vue.use(Share);
Vue.use(Toast);

Vue.filter("date", function(value) {
  return moment(value).format("YYYY-MM-DD");
});

Vue.filter("hour", function(value) {
  return moment(value).format("HH:mm:ss");
});

Vue.filter("num", function(value) {
  if (value >= 1000) {
    return (value / 1000).toFixed(1) + "k";
  }
  return value;
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

router.afterEach(() => {
  window.scrollTo({
    top: 0,
    behavior: "instant"
  });
  NProgress.done();
});

axios.interceptors.response.use(
    function(response) {
      switch (response.data.code) {
        case 50000:
          Vue.prototype.$toast({ type: "error", message: "系统异常" });
      }
      return response;
    },
    function(error) {
      return Promise.reject(error);
    }
);

new Vue({
  router,
  store,
  vuetify,
  render: h => h(App)
}).$mount('#app')
